package map;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;

public class TreeMapTest {

	public static void main(String[] args) {
		// HashMap
		Map<String, Object> hashMap = new HashMap<>();
		hashMap.put("2", "b");
		hashMap.put("12", "c");
		hashMap.put("13", "d");
		hashMap.put("3", "a");
		hashMap.put("8", "bd");
		hashMap.put("1", "bs");
		hashMap.put("0", "db");
		hashMap.put("10", "cb");
		hashMap.put("9", "sd");
		hashMap.put("6", "34");
		System.out.println("hashMap:" + hashMap.toString());
		
		// TreeMap
		Map<String, Object> treeMap = new TreeMap<>();
		treeMap.put("2", "sd");
		treeMap.put("12", "sd");
		treeMap.put("13", "sb");
		treeMap.put("3", "bd");
		treeMap.put("8", "e");
		treeMap.put("1", "bf");
		treeMap.put("0", "gb");
		treeMap.put("10", "1b");
		treeMap.put("9", "b2");
		treeMap.put("6", "sdfs");
		System.out.println("treeMap:" + treeMap.toString());
		
		// SortedMap
		SortedMap<Integer, Object> sortedMap = new TreeMap<>();
		sortedMap.put(2, "1");
		sortedMap.put(1, "0");
		sortedMap.put(11, "1ab");
		sortedMap.put(22, "2");
		sortedMap.put(12, "1ab");
		sortedMap.put(15, "2");
		sortedMap.put(0, "2ab");
		sortedMap.put(7, "a2b");
		sortedMap.put(5, "1b");
		sortedMap.put(3, "a1b");
		sortedMap.put(8, "ab2");
		sortedMap.put(9, "sab");
		sortedMap.put(20, "2");
		System.out.println("sortedMap:" + sortedMap.toString());
		System.out.println("sortedMap.subMap:" + sortedMap.subMap(10, 20));
		
		// NavigableMap
		NavigableMap<Integer, Integer> navigableMap = new TreeMap<>();
	    for (int i = 0; i < 10; i++) {
	    	navigableMap.put(i, i);
	    }
		System.out.println("navigableMap:" + navigableMap.toString());
		System.out.println("lowerEntry(6).getKey():" + navigableMap.lowerEntry(6).getKey());
		System.out.println("lowerEntry(5).getKey():" + navigableMap.lowerEntry(5).getKey());
		System.out.println("lowerEntry(0).getKey():" + navigableMap.lowerEntry(0));
	}

}
